package com.allinpay.payment.controller;

import com.alibaba.csp.sentinel.EntryType;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.allinpay.payment.SignService;
import com.allinpay.payment.handler.SentinelExceptionHandler;
import com.allinpay.until.requestModel.TpReq;
import com.allinpay.until.responseModel.TpRet;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


@Slf4j
@RestController
@RequestMapping("/gateway")
public class GatewayController {

    @Autowired
    private SignService signService;

    @SentinelResource(value = "sign", entryType = EntryType.OUT, blockHandlerClass = SentinelExceptionHandler.class, blockHandler = "signExceptionHandle")
    @RequestMapping(value = "sign", method = RequestMethod.GET)
    public String sign(@RequestParam("name") String name) {
        log.info("进入收单前置:签约名{}", name);
        TpReq tpReq = new TpReq();
        tpReq.setName(name);
        TpRet sign = signService.sign(tpReq);
        return sign.getName();
    }
}
